home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
TEMP
/
GNU
/
flex
/
Miscellane
< prev
next >
Wrap
Text File
|
1995-06-28
|
3KB
|
73 lines
Miscellaneous
Previous: <End-of-file rules=>Endoffiler> * Next: <User variables=>Uservariab> * Up: <Top=>!Root>
#Wrap on
{fH3}Miscellaneous macros{f}
The macro {fCode}YY\_USER\_ACTION{f} can be defined to provide an
action which is always executed prior to the matched
rule's action. For example, it could be \#define'd to call
a routine to convert yytext to lower-case. When
{fCode}YY\_USER\_ACTION{f} is invoked, the variable {fCode}yy\_act{f} gives the
number of the matched rule (rules are numbered starting
with 1). Suppose you want to profile how often each of
your rules is matched. The following would do the trick:
#Wrap off
#fCode
\#define YY\_USER\_ACTION ++ctr[yy\_act]
#f
#Wrap on
where {fCode}ctr{f} is an array to hold the counts for the different
rules. Note that the macro {fCode}YY\_NUM\_RULES{f} gives the total number
of rules (including the default rule, even if you use {fEmphasis}-s{f}, so
a correct declaration for {fCode}ctr{f} is:
#Wrap off
#fCode
int ctr[YY\_NUM\_RULES];
#f
#Wrap on
The macro {fCode}YY\_USER\_INIT{f} may be defined to provide an action
which is always executed before the first scan (and before
the scanner's internal initializations are done). For
example, it could be used to call a routine to read in a
data table or open a logging file.
The macro {fEmphasis}yy\_set\_interactive(is\_interactive){f} can be used
to control whether the current buffer is considered
{fEmphasis}interactive{f}. An interactive buffer is processed more slowly,
but must be used when the scanner's input source is indeed
interactive to avoid problems due to waiting to fill
buffers (see the discussion of the {fEmphasis}-I{f} flag below). A
non-zero value in the macro invocation marks the buffer as
interactive, a zero value as non-interactive. Note that
use of this macro overrides {fEmphasis}%option always-interactive{f} or
{fEmphasis}%option never-interactive{f} (see Options below).
{fEmphasis}yy\_set\_interactive(){f} must be invoked prior to beginning to
scan the buffer that is (or is not) to be considered
interactive.
The macro {fEmphasis}yy\_set\_bol(at\_bol){f} can be used to control
whether the current buffer's scanning context for the next
token match is done as though at the beginning of a line.
A non-zero macro argument makes rules anchored with
The macro {fEmphasis}YY\_AT\_BOL(){f} returns true if the next token
scanned from the current buffer will have '^' rules
active, false otherwise.
In the generated scanner, the actions are all gathered in
one large switch statement and separated using {fCode}YY\_BREAK{f},
which may be redefined. By default, it is simply a
"break", to separate each rule's action from the following
rule's. Redefining {fCode}YY\_BREAK{f} allows, for example, C++
users to \#define YY\_BREAK to do nothing (while being very
careful that every rule ends with a "break" or a
"return"!) to avoid suffering from unreachable statement
warnings where because a rule's action ends with "return",
the {fCode}YY\_BREAK{f} is inaccessible.